home *** CD-ROM | disk | FTP | other *** search
/ Exame Informatica 140 / Exame Informatica 140.iso / Internet / Adblock / adblock-0.5.3.043-fx+fl+mz+ns.xpi / install.js < prev    next >
Text File  |  2006-06-30  |  10KB  |  232 lines

  1. /*
  2. ** authored by rue
  3. */
  4.  
  5. /* Pre-Install Cleanup (for prior versions) */
  6.  
  7. // temp-dir
  8. initInstall("pre-install", "/tempDir", "0.0"); // dummy-install - allows committance of file-operations
  9. var tempDir = getFolder(getFolder("Profile", "chrome"), "adblock-temp"); // adblock temp-dir
  10. if (!File.exists(tempDir)) dirCreate(tempDir); // create temp-dir if it doesn't exist
  11. performInstall(); // commit dir-creation changes
  12.  
  13. // file-check array
  14. var dirArray = new Array(), d;
  15. dirArray.push((d=[]));
  16.     d.push(getFolder("Profile", "chrome"));    // profile-chrome
  17.     d.push("adblock");                         // filename - profile jar
  18.     d.push(".jar");                         // filename - extension
  19. dirArray.push((d=[]));
  20.     d.push(getFolder("chrome"));            // app-chrome
  21.     d.push("adblock");                         // filename - root jar
  22.     d.push(".jar");                         // filename - extension
  23. dirArray.push((d=[]));
  24.     d.push(getFolder("components"));        // app-components
  25.     d.push("nsAdblock");                     // filename - root component
  26.     d.push(".js");                             // filename - extension
  27. dirArray.push((d=[]));
  28.     d.push(getFolder("Profile"));            // profile
  29.     d.push("XUL FastLoad File");             // filename - xul cache mac
  30.     d.push("");                             // filename - extension
  31. dirArray.push((d=[]));
  32.     d.push(getFolder("Profile"));            // profile
  33.     d.push("XUL");                             // filename - xul cache macosX
  34.     d.push(".mfast");                         // filename - extension
  35. dirArray.push((d=[]));
  36.     d.push(getFolder("Profile"));            // profile
  37.     d.push("XUL");                             // filename - xul cache linux
  38.     d.push(".mfasl");                         // filename - extension
  39. dirArray.push((d=[]));
  40.     d.push(getFolder("Profile"));            // profile
  41.     d.push("XUL");                             // filename - xul cache windows
  42.     d.push(".mfl");                         // filename - extension
  43. dirArray.push((d=[]));
  44.     d.push(getFolder(getFolder("Profile"),'components'));// profile-components
  45.     d.push("nsAdblock");                     // filename - root component
  46.     d.push(".js");                             // filename - extension
  47. dirArray.push((d=[]));
  48.     d.push(getFolder(getFolder("Profile"),"pref"));// profile prefs
  49.     d.push("adblock");                         // filename - pref defaults
  50.     d.push(".js");                             // filename - extension
  51.  
  52. var currentInProfile = false;
  53. var currentInRoot = false;
  54.  
  55. // file-check loop
  56. for (var i = 0 ; i < dirArray.length ; i++) {
  57.     initInstall("pre-install - 0."+i, "/rename", "0."+i); // reopen dummy-install
  58.     var currentDir = dirArray[i][0];
  59.     var nameMain = dirArray[i][1];
  60.     var nameEnd = dirArray[i][2];
  61.     var tempDir = getFolder(getFolder("Profile", "chrome"), "adblock-temp"); // adblock temp-dir
  62.     if (!File.exists(tempDir)) dirCreate(tempDir); // create temp-dir if it doesn't exist
  63.     var previousFile = getFolder(currentDir, nameMain + nameEnd); // previous jar
  64.     var newNameMain = "adblock-uninstalled";// nameMain + "-uninstalled";
  65.     var newName = newNameMain; // + nameEnd;
  66.     var n = 1;
  67.     
  68.     if (File.exists(previousFile)) {
  69.         if (File.exists(getFolder(currentDir, newName))) // <-- change 'currentDir' to 'tempDir' to revert: old-style
  70.             while(File.exists(getFolder(currentDir, newName))) { // <-- ditto.
  71.                 newName = new String(newNameMain + n); // + nameEnd); // find a unique-name for our "move-to" destination
  72.                 n++;
  73.             }
  74.         // rename file
  75.         File.rename(previousFile, newName); // rename the previous jar to the unique-name
  76.         performInstall(); // commit file-rename changes
  77.         
  78.         // -- this can be (un)commented without worry.. it just seemingly fails to move, every time
  79.         // move file
  80.         initInstall("pre-install", "/move", "0."+i); // reopen dummy-install
  81.         if (!File.exists(previousFile)) previousFile = getFolder(currentDir, newName); // if successfully renamed, get the file by its new name
  82.         File.move(previousFile, tempDir); // move jar to temp-dir
  83.         performInstall(); // commit file-move changes
  84.         
  85.         // delete original
  86.         initInstall("pre-install", "/delete", "0."+i); // reopen dummy-install
  87.         if (File.exists(previousFile)) File.remove(previousFile); // delete original (in case it didn't completely move)
  88.         performInstall(); // commit file-deletion changes
  89.         
  90.         switch(i) {
  91.             case 0: currentInProfile = true; break;
  92.             case 1: currentInRoot    = true; break; }
  93.     }
  94.     
  95. }
  96.  
  97. const alreadyInstalled = currentInProfile||currentInRoot;
  98.  
  99.  
  100. /* Main Install Routine */
  101.  
  102. // only load after the Pre-Install Cleanup completes
  103. if (true) {
  104.     // install constants
  105.     const APP_DISPLAY_NAME = "Adblock";
  106.     const APP_NAME = "adblock";
  107.     const APP_PACKAGE = "/adblock.mozdev.org";
  108.     const APP_VERSION = "0.5";
  109.     
  110.     const APP_JAR_FILE = "adblock.jar";
  111.     const APP_JAR_LOC = 'chrome/' + APP_JAR_FILE;
  112.     
  113.     const APP_REG_FILE = "components/.autoreg";
  114.     const APP_COMP_FILE = "components/nsAdblock.js";
  115.     const APP_COMP_LOC = APP_COMP_FILE;
  116.     
  117.     const APP_SKIN_FOLDER = "skin/classic/";
  118.     var   APP_LOCALE_FOLDERS = [];
  119.         //APP_LOCALE_FOLDERS.push("content/sessionsaver/main-locale/en-US/sessionsaver/"); // default fallback-locale
  120.         //APP_LOCALE_FOLDERS.push("locale/nl-NL/sessionsaver/");
  121.     var  NEW_APP_LOCALE_FOLDERS = [];
  122.         // ..add new app-locales here, so they'll be registered even if only updating
  123.     
  124.     const APP_CONTENT_FOLDER = "content/";
  125.     
  126.     const INST_TO_PROFILE = "Install "+APP_DISPLAY_NAME+" in your profile?\n(..you wont have to reinstall when updating the browser).\n\nClick Cancel to install "+APP_DISPLAY_NAME+" in the browser root.";
  127.     const ROOT_FAILED___TRY_INST_TO_PROFILE = "You didn't have permission to install as root.\n Would you like to force profile-installation?\n\n[Note: "+APP_DISPLAY_NAME+" WILL NOT FUNCTION in the profile for browsers-builds older than 6.24.03. This includes moz1.4.1 and fb.6]";
  128.     
  129.     const profileChrome = getFolder("Profile", "chrome");
  130.     const previousJarInProfile = getFolder(profileChrome, "adblock.jar");
  131.     const previousJarInRoot = getFolder("chrome", "adblock.jar"); }
  132.  
  133.  
  134.  
  135. // initialize our install
  136. initInstall(APP_NAME, APP_PACKAGE, APP_VERSION);
  137.  
  138.  
  139. // check for previous install
  140. if (File.exists(previousJarInProfile) || File.exists(previousJarInRoot)) {
  141.     
  142.     var installedHere = File.exists(previousJarInProfile)?"profile ":"";
  143.     installedHere += (File.exists(previousJarInProfile) && File.exists(previousJarInRoot))?"*and* ":"";
  144.     installedHere += File.exists(previousJarInRoot)?"root ":"";
  145.     installedHere += (File.exists(previousJarInProfile) && File.exists(previousJarInRoot))?"directories":"directory";
  146.  
  147.     alert("Sorry:  Adblock is already installed in your " + installedHere + ". "
  148.         +"\n\n\n\nIf you're running a recent dev-build, you can deinstall from preferences. "
  149.         +"\nFor all other versions, please consult the online-faq:"
  150.         +"\n\nadblock.mozdev.org/faq.html");
  151.     cancelInstall(-23); // we can't overwrite, so don't install further
  152.     
  153. }
  154. else {
  155.  
  156.     // runtime component registration only works since 2003-06-24..
  157.     var instToProfile = false;
  158.     if (alreadyInstalled) instToProfile = currentInProfile;
  159.     else if (buildID == 0 || buildID > 2003062400) instToProfile = confirm(INST_TO_PROFILE); // ..so, dont ask on prior builds.
  160.     
  161.     // Add comp file
  162.     //if (!instToProfile) {
  163.         var compDir = getFolder(getFolder('Program'),'components');
  164.         if (!File.exists(getFolder(compDir,".autoreg"))) addFile(null, APP_REG_FILE, compDir, null);
  165.         
  166.         var errComponent = addFile(null, APP_COMP_FILE, compDir, null);
  167.         if (errComponent != SUCCESS && instToProfile) alert("Adblock's Component failed to install.\n\nDon't worry- Adblock will attempt to install this file again, \nat startup. Just make sure you have write-privileges for \nthe application folder.");
  168.     //}
  169.     
  170.     
  171.     // install jar-file
  172.     var chromef = instToProfile ? getFolder("Profile", "chrome") : getFolder("chrome");
  173.     var errJar = addFile(APP_PACKAGE, APP_VERSION, APP_JAR_LOC, chromef, null);
  174.     
  175.     
  176.     // if root-install was attempted and failed, ask the user what to do
  177.     if(!instToProfile && (errComponent != SUCCESS || errJar != SUCCESS)) {
  178.         instToProfile = confirm(ROOT_FAILED___TRY_INST_TO_PROFILE);
  179.         if (instToProfile) {
  180.             chromef = getFolder("Profile", "chrome");
  181.             errJar = addFile(APP_PACKAGE, APP_VERSION, APP_JAR_LOC, chromef, null); }
  182.         else errJar = "root install failed";
  183.     }
  184.     
  185.     
  186.     // Add profile-copy of component, for startup-installation
  187.     if (instToProfile) {
  188.         var profChromef = getFolder("Profile", "chrome");
  189.         errComponent = addFile(null, APP_COMP_FILE, profChromef, null);
  190.         addFile(null, APP_REG_FILE, profChromef, null);
  191.     }
  192.  
  193.     // if we've successfully installed the files, register them
  194.     if (errJar == SUCCESS && errComponent == SUCCESS) {
  195.         var jar = getFolder(chromef, APP_JAR_FILE);
  196.         var chrome_dest = (instToProfile) ? PROFILE_CHROME : DELAYED_CHROME;
  197.         
  198.         if (alreadyInstalled) { //;} // *ding -- update success.
  199.             for(var j = 0; i < NEW_APP_LOCALE_FOLDERS.length; ++j) 
  200.                 registerChrome(LOCALE | chrome_dest, jar, NEW_APP_LOCALE_FOLDERS[j]);
  201.         }
  202.         else {
  203.             registerChrome(CONTENT | chrome_dest, jar, APP_CONTENT_FOLDER);
  204.             //registerChrome(SKIN | chrome_dest, jar, APP_SKIN_FOLDER);
  205.             for(var k = 0; k < APP_LOCALE_FOLDERS.length; ++k) 
  206.                 registerChrome(LOCALE | chrome_dest, jar, APP_LOCALE_FOLDERS[k]);
  207.         }
  208.         
  209.         // Add prefs file -- only after successful install of others
  210.         var prefDir = getFolder(getFolder("Profile"),"pref");
  211.         if (!File.exists(prefDir)) dirCreate(prefDir);
  212.         if (!File.exists(getFolder(prefDir,APP_NAME+".js"))) 
  213.             addFile(null, "defaults/preferences/" + APP_NAME + ".js", prefDir, null);
  214.         
  215.         // Commit install
  216.         var err = performInstall();
  217.         if (err == SUCCESS || err == 999) {
  218.             alert(APP_DISPLAY_NAME + " " + APP_VERSION + " is now installed.\n"
  219.                 +"Just restart to activate."); } 
  220.         else {
  221.             alert("Install failed. Error code:" + err);
  222.             cancelInstall(err); }
  223.     } 
  224.     else {
  225.         alert("Failed to create " +APP_JAR_FILE +"\n"
  226.             +"You probably don't have appropriate permissions \n"
  227.             +"(write access to your profile or chrome directory). \n"
  228.             +"_____________________________\nError code:" + errJar);
  229.         cancelInstall(errJar);
  230.     }
  231.     
  232. }